package cn.sirun.com.fca.account.uitl;

import android.text.TextUtils;


import com.tencent.cloud.iov.util.storage.TXCacheManager;

import java.util.HashMap;
import java.util.Map;

import cn.sirun.com.fca.account.constant.AccountCommonConst;
import cn.sirun.com.fca.account.constant.RequestParamConst;
import cn.sirun.com.fca.account.model.base.CarData;
import cn.sirun.com.fca.account.model.base.OwnerInfo;
import cn.sirun.com.fca.account.model.bind.SubmitCarInfoRequest;

/**
 * @author vinsonhuang
 * @date 2018/6/8
 */
public class StorageUtils {

    /**
     * 临时保存车辆信息
     *
     * @param carData
     */
    public static void saveCarInfo(CarData carData) {
        saveAuthInfo(RequestParamConst.PictureTypeEnum.VEHICLE_LICENSE,
                carData.getUrl(), carData.getOwner(),
                carData.getEngineId(), carData.getCarNumber());
    }

    /**
     * 临时保存所有者身份信息
     *
     * @param ownerInfo
     */
    public static void saveOwnerInfo(OwnerInfo ownerInfo) {
        saveAuthInfo(RequestParamConst.PictureTypeEnum.IDENTITY_CARD,
                ownerInfo.getUrl(), ownerInfo.getName(), ownerInfo.getId(), null);
    }

    /**
     * 临时保存认证信息
     */
    public static void saveAuthInfo(SubmitCarInfoRequest request) {
        if (null == request) {
            return;
        }
        saveAuthInfo(RequestParamConst.PictureTypeEnum.VEHICLE_LICENSE, request.getUrl(),
                request.getOwner(), request.getEngineId(), request.getCarNumber());
    }

    /**
     * 临时保存认证信息
     *
     * @param pictureType
     * @param ownerOrName
     * @param engineIdOrIdentity
     * @param vehicleIdentityNumber
     */
    public static void saveAuthInfo(RequestParamConst.PictureTypeEnum pictureType,
                                    String url, String ownerOrName, String engineIdOrIdentity,
                                    String vehicleIdentityNumber) {
        Map<String, String> values = new HashMap<>(4);
        if (!TextUtils.isEmpty(url)) {
            values.put(AccountCommonConst.AUTH_URL, url);
        }
        if (!TextUtils.isEmpty(ownerOrName)) {
            values.put(AccountCommonConst.OWNER_OR_NAME, ownerOrName);
        }
        if (!TextUtils.isEmpty(engineIdOrIdentity)) {
            values.put(AccountCommonConst.ENGINE_ID_OR_IDENTITY, engineIdOrIdentity);
        }
        if (!TextUtils.isEmpty(vehicleIdentityNumber)) {
            values.put(AccountCommonConst.VEHICLE_IDENTITY_NUMBER, vehicleIdentityNumber);
        }
        if (!values.isEmpty()) {
            TXCacheManager.getInstance().setMap(pictureType.name(), values);
        }
    }

    /**
     * 获取认证信息
     *
     * @param pictureType
     * @return
     */
    public static Map<String, String> getAuthInfo(RequestParamConst.PictureTypeEnum pictureType) {
        return TXCacheManager.getInstance().getMap(pictureType.name());
    }

    /**
     * 删除认证信息
     *
     * @param pictureType
     */
    public static void removeAuthInfo(RequestParamConst.PictureTypeEnum pictureType) {
        TXCacheManager.getInstance().remove(pictureType.name());
    }
}
